home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / AOF / DECAOF / decaof / mkendian_c < prev    next >
Text File  |  1992-11-20  |  910b  |  44 lines

  1. /*
  2.  * Determine byte-sex of local host to enable RISC OS (little endian) files
  3.  * to be read/written.
  4.  *
  5.  * Andy Duplain, BT Customer Systems, Brighton, UK.  duplain@btcs.bt.co.uk
  6.  */
  7.  
  8. #include <stdio.h>
  9.  
  10. void
  11. main()
  12. {
  13.     register i;
  14.     union {
  15.         unsigned long l;
  16.         unsigned short w;
  17.         char c[4];
  18.     } x;
  19.  
  20.     if (sizeof(x.l) != 4 || sizeof(x.w) != 2) {
  21.         fprintf(stderr, "size mismatch in union... aborting\n");
  22.         exit(1);
  23.     }
  24.  
  25.     puts("/* endian.h:  local host specific byte-sex defines */");
  26.     puts("#ifndef __ENDIAN_H");
  27.     puts("#define __ENDIAN_H");
  28.     x.l = 0x00010203;
  29.     if (x.c[0] == 3 && x.c[1] == 2 && x.c[2] == 1 && x.c[3] == 0)
  30.         puts("#define LITTLE_ENDIAN");
  31.     else
  32.         puts("#undef LITTLE_ENDIAN");
  33.     for (i = 0; i < 4; i++)
  34.         printf("#define WORD%d\t%d\n", i, 3 - x.c[i]);
  35.  
  36.     x.w = 0x0001;
  37.  
  38.     for (i = 0; i < 2; i++)
  39.         printf("#define HALFWORD%d\t%d\n", i, 1 - x.c[i]);
  40.  
  41.     puts("#endif /* __ENDIAN_H */");
  42.     exit(0);
  43. }
  44.